﻿@{
    ViewBag.Title = "ValueForm";
    Layout = "~/Views/Shared/_FlowForm.cshtml";
}

<script>
    var keyValue = request('keyValue');
    $(function () {
        //标识方式选择
        $("#Flag .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#Flag .dropdown-text").html(text).attr('data-value', value);
        });
        $("#ColorBtn").bind("change", function () {
            $("#Color").val(this.value);
            $("#ColorBtn").val("");
        });
        var mycolor = $("#ColorBtn").cxColor();
        $("#ColorBtn").css("background-color", "#00FF00");
        $("#Color").val("#00FF00");
        //获取表单
        if (!!keyValue) {
            var rowdata = top.frames["Form1"].$("#gridTable1").jqGridRow()[0];
            $("#form1").SetWebControls(rowdata);
            rowdata.Color = rowdata.Color.substring(40, 47);
            $("#ColorBtn").css("background-color", rowdata.Color);
            $("#Color").val(rowdata.Color);
            switch (rowdata.Flag) {
                case "0": $("#Flag .dropdown-text").html(">").attr('data-value', rowdata.Flag); break;
                case "1": $("#Flag .dropdown-text").html("≥").attr('data-value', rowdata.Flag); break;
                case "2": $("#Flag .dropdown-text").html("=").attr('data-value', rowdata.Flag); break;
                case "3": $("#Flag .dropdown-text").html("≤").attr('data-value', rowdata.Flag); break;
                case "4": $("#Flag .dropdown-text").html("<").attr('data-value', rowdata.Flag); break;
                case "5": $("#Flag .dropdown-text").html("~").attr('data-value', rowdata.Flag); break;
                default: break;
            }
        }
    });


    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        if (!$('#MinValue').val() && !$('#MaxValue').val()) {
            dialogMsg("请输入至少一个界限值。", 7);
            return false;
        }
        var $gridTable = top.frames["Form1"].$("#gridTable1");
        var postData = $("#form1").GetWebControls("");
        postData["Id"] = newGuid();
        if (!!$('#MinValue').val() && !!$('#MaxValue').val()) {
            postData["ValueMemo"] = $('#MinValue').val() + "到" + $('#MaxValue').val();
            postData["Flag"] = 5;
        } else {
            postData["Flag"] = $("#Flag .dropdown-text").attr("data-value");
            switch (postData["Flag"]) {
                case "0": postData["ValueMemo"] = !!$('#MinValue').val() ? "小于" + $('#MinValue').val() : "大于" + $('#MaxValue').val(); break;
                case "1": postData["ValueMemo"] = !!$('#MinValue').val() ? "小于等于" + $('#MinValue').val() : "大于等于" + $('#MaxValue').val(); break;
                case "2": postData["ValueMemo"] = !!$('#MinValue').val() ? "等于" + $('#MinValue').val() : "等于" + $('#MaxValue').val(); break;
                case "3": postData["ValueMemo"] = !!$('#MinValue').val() ? "大于等于" + $('#MinValue').val() : "小于等于" + $('#MaxValue').val(); break;
                case "4": postData["ValueMemo"] = !!$('#MinValue').val() ? "大于" + $('#MinValue').val() : "小于" + $('#MaxValue').val(); break;
                case "5": postData["ValueMemo"] = !!$('#MinValue').val() ? "大于等于" + $('#MinValue').val() : "小于等于" + $('#MaxValue').val(); postData["Flag"] = 1; break;
                default: break;
            }
        }
        if (!!keyValue) {
            $gridTable.setRowData(keyValue, postData);
        } else {
            $gridTable.addRowData(($gridTable.jqGrid("getRowData").length + 1), postData);
        }
        dialogMsg("操作成功。", 1);
        dialogClose();
    }
</script>
<div style="margin-top: 40px; margin-right: 30px;">
    <table class="form">
        <tr class="TypeValue">
            <th class="formTitle">界限值1</th>
            <td class="formValue">
                <input id="MinValue" placeholder="最 少输入一个界限值" type="number" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">符号</th>
            <td class="formValue">
                <div id="Flag" class="btn-group" style="width:100%;">
                    <a class="btn btn-default dropdown-text" data-value="2" data-toggle="dropdown" style="width:89%">=</a>
                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                    <ul class="dropdown-menu" style="width:89%">
                        <li><a data-value="0">></a></li>
                        <li><a data-value="1">≥</a></li>
                        <li><a data-value="2">=</a></li>
                        <li><a data-value="3">≤</a></li>
                        <li><a data-value="4"><</a></li>
                        <li><a data-value="5">~</a></li>
                    </ul>
                </div>
            </td>
        </tr>
        <tr>
            <th class="formTitle">界限值2</th>
            <td class="formValue">
                <input id="MaxValue" placeholder="最少输入一个界限值" type="number" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">颜色</th>
            <td class="formValue">
                <input type="hidden" id="Color" value="#00FF00" />
                <input type="button" style="width: 40%; background-color: #00FF00; " class="form-control" id="ColorBtn" />
            </td>
        </tr>
    </table>
</div>